package com.market.web.model;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.market.domain.OrderDetail;
import com.market.domain.Product;
import com.market.domain.Purchase;
import com.market.domain.PurchaseDetail;

@Component("purchaseModel")
@Scope("session")
public class PurchaseModel extends GenericModel<Purchase> {
	
	private PurchaseDetail currentPurchaseDetail;
	
	public List<SelectItem> getAvailableStatus() {
		List<SelectItem> statuses = new ArrayList<SelectItem>();
		for (Purchase.STATUS status : Purchase.STATUS.values()) {
			statuses.add(new SelectItem(status, status.getLabel()));
		}
		return statuses;
	}

	@Override
	public Purchase getNewObject() {
		Purchase purchase = new Purchase();
		purchase.setIsNew(true);
		this.setCurrent(purchase);
		return purchase;
	}
	
	public PurchaseDetail createPurchaseDetail(Product product){
		PurchaseDetail purchaseDetail = new PurchaseDetail();
		purchaseDetail.setProduct(product);
		purchaseDetail.setIsNew(true);
		purchaseDetail.setPurchasedQuantity(1);
		purchaseDetail.setPurchasedPrice(product.getPurchasePrice());
		
		return purchaseDetail;
	}

	public PurchaseDetail getCurrentPurchaseDetail() {
		return currentPurchaseDetail;
	}

	public void setCurrentPurchaseDetail(PurchaseDetail currentPurchaseDetail) {
		this.currentPurchaseDetail = currentPurchaseDetail;
	}

	
	
}
